<template>
  <div id="coupon">  
      <div  style="display:flex;margin-bottom:10px;align-items: center;">
            <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
            <div style="line-height: 40px;font-weight:bold:">金蜜券</div>
     </div> 
  
  <el-form ref="form"  label-width="0px">  
    <el-row>
        <el-col  :span="14" style="display:flex;">
            <el-form-item label="">
                <el-select  v-model="select_num" placeholder="请选择" @change="select_change" style="width:160px;">
                    <el-option  v-for="(item,index) in select_data" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

             <el-form-item label="" label-width="0px" style="margin-left:10px;">
                 <el-date-picker type="date"  placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="form.time" style="width:160px;"></el-date-picker>
            </el-form-item>

             <el-form-item label-width="0px" style="margin-left:10px;">
                  <el-input v-model="form.phone" placeholder="姓名/手机号" style="width:160px;"></el-input>
             </el-form-item>

               <div class="custom_button2"  style="margin-left:10px;" @click="search_but()"></div>
        </el-col> 
     

        <el-col :span="10" style="text-align: right;">    
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;"  @click="refresh_but()">刷新</el-button>
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="set_but_jdq()">
               <img class="custom_color_button1_img" src="@/assets/images/but_bg9.png" /> {{ variable_name2 }}券比例
            </el-button>   
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="set_but_jd()">
                <img class="custom_color_button1_img" src="@/assets/images/but_bg6.png" />{{ variable_name2 }}设置
            </el-button>       
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="set_but_gm()">
                <img class="custom_color_button1_img" src="@/assets/images/but_bg6.png" />{{ variable_name1 }}设置
            </el-button>         
        </el-col>
   
  </el-row>
  </el-form >

   <!-- 渲染数据list -->
   <coupon-list :datalist="datalist" @up_list_fun="list_fun"> </coupon-list>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>


    <!-- 设置果米 -->
        <el-dialog :title="'设置' + variable_name1" :visible.sync="mtk1"  width="350px">
            <div style="width:100%;"> 
           
            <el-form ref="form" :model="formlist"   label-width="100px" style="width:100%;">  
                <el-row>         
                    <el-form-item label="" label-width="0px">
                       <el-input    v-model="formlist.kmb_number" placeholder="请输入"></el-input>
                    </el-form-item> 
                </el-row> 
            </el-form>

            <div style="text-align: center;width:70%;margin:auto;">
                <el-button type="primary" style="width:80%;" class="custom_color_button" @click="gm_but_qr()">确认</el-button>
            </div>

            </div> 
        </el-dialog>

        <!-- 设置金豆 -->
        <el-dialog :title="'设置' + variable_name2" :visible.sync="mtk2"  width="350px">
            <div style="width:100%;"> 
           
            <el-form ref="form" :model="formlist"   label-width="100px" style="width:100%;">  
                <el-row>         
                    <el-form-item label="" label-width="0px">
                       <el-input    v-model="formlist.gdb_number" placeholder="请输入"></el-input>
                    </el-form-item> 
                </el-row> 
            </el-form>

            <div style="text-align: center;width:70%;margin:auto;">
                <el-button type="primary" style="width:80%;" class="custom_color_button" @click="jd_but_qr()">确认</el-button>
            </div>

            </div> 
        </el-dialog>

         <!-- 设置金豆券比例 -->
        <el-dialog :title="'设置' + variable_name2 +'券比例'" :visible.sync="mtk3"  width="350px">
            <div style="width:100%;"> 
           
            <el-form ref="form" :model="form_jdq"   label-width="100px" style="width:100%;">  
                <el-row>         
                    <el-form-item label="" label-width="0px">
                       <el-input    v-model="form_jdq.number" placeholder="请输入比例"></el-input>
                    </el-form-item> 
                </el-row> 
            </el-form>

            <div style="text-align: center;width:70%;margin:auto;">
                <el-button type="primary" style="width:80%;" class="custom_color_button" @click="jdq_but_qr()">确认</el-button>
            </div>

            </div> 
        </el-dialog>
      
  </div>
</template>

<script>
import CouponList from '@/view/Jindou/CouponList'
export default {
  name: 'coupon',
  data () {
    return {
        datalist:[],
        page:1,
        count:0,
        select_num:'',
        form:{
            phone:'',
            time:''
        },
        select_data:[{"id":1,"name":"申请中"},{"id":2,"name":"已完成"},{"id":3,"name":"已驳回"}],
        formlist:{
           kmb_number:'',
           gdb_number:'',
        },
        mtk1:false,
        mtk2:false,
        mtk3:false,
        form_jdq:{
            number:''
        }
     
    }
  },
 components:{
    CouponList
  },
  created(){
      this.list_fun()
      this.list_fun_set()
  },
  mounted (){
    
  },
  methods: { 
      list_fun(){
           this.post("/gdb_ticket/listOfApply", {
              page:this.page,
              type:this.select_num,
              telphone:this.form.phone
	        }).then(res => {
              this.count = res.result.count
              this.datalist = res.result.list
              //console.log(res,"aaacc")
         })
      },
      search_but(){
          this.page = 1
          this.list_fun()
      },
       refresh_but(){
           this.page = 1
           this.select_num = ''
           this.form.phone = ''
           this.list_fun()
      },
      list_fun_set(){
            this.post("gdb_ticket/exchangeNeed", {
	        }).then(res => {
                console.log(res,"sssss")
               this.formlist.kmb_number = res.result.need_kmb_number
               this.formlist.gdb_number = res.result.need_gdb_number
               this.form_jdq.number = res.result.send_limit_number
            })
      },
      select_change(){
         this.page = 1
         this.list_fun()
      },
      set_but_gm(){
          this.mtk1 = true
          this.list_fun_set()
      },
      gm_but_qr(){
          this.post("/gdb_ticket/setExchangeNeedKmb", {
                   kmb_number:this.formlist.kmb_number
                }).then(res => {

                    if(res.error_code == 0){
                        this.open1(res.result,'success')  //提示框
                        this.list_fun_set()
                        this.mtk1 = false

                    }else {
                        this.open1(res.message,'warning')
                    }
               })
      },
      set_but_jd(){
          this.mtk2 = true
          this.list_fun_set()
      },
      jd_but_qr(){
          this.post("/gdb_ticket/setExchangeNeedGdb", {
                   gdb_number:this.formlist.gdb_number
                }).then(res => {

                    if(res.error_code == 0){
                        this.open1(res.result,'success')  //提示框
                        this.list_fun_set()
                        this.mtk2 = false

                    }else {
                        this.open1(res.message,'warning')
                    }
               })
      },
      set_but_jdq(){
          this.mtk3 = true
          this.list_fun_set()
      },
      jdq_but_qr(){
          this.post("/gdb_ticket/setSendNumber", {
                   send_limit_number:this.form_jdq.number
                }).then(res => {

                    if(res.error_code == 0){
                        this.open1(res.result,'success')  //提示框
                        this.list_fun_set()
                        this.mtk3 = false
                    }else {
                        this.open1(res.message,'warning')
                    }
               })
      },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>

</style>
